package la.bbs558.controller.user;

import com.baomidou.mybatisplus.core.metadata.IPage;
import la.bbs558.aop.valid.Check;
import la.bbs558.controller.base.BaseController;
import la.bbs558.controller.base.Result;
import la.bbs558.entity.UserPointsLog;
import la.bbs558.entity.enums.UserOpt;
import la.bbs558.entity.params.UserPointsPage;
import la.bbs558.service.UserPointsLogService;
import la.bbs558.util.EnumUtils;
import la.bbs558.util.Objs;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Classname UserController
 * @Description 用户积分
 * @Date 2023/12/15 10:27
 * @Created by weihanmin
 */
@RestController
@RequestMapping("user/point")
@Check
public class UserPointController extends BaseController {
    @Resource
    private UserPointsLogService userPointsLogService;

    @GetMapping("list")
    public Result<?> list(UserPointsPage page) {
        IPage<UserPointsLog> res = userPointsLogService
                .lambdaQuery()
                .eq(Objs.isValid(page.getOptType()), UserPointsLog::getOptType, page.getOptType())
                .ge(Objs.isValid(page.getCreateStTime()), UserPointsLog::getCreateTime, page.getCreateStTime())
                .le(Objs.isValid(page.getCreateEdTime()), UserPointsLog::getCreateTime, page.getCreateEdTime())
                .page(page);
        return Result.success(res);
    }

    @GetMapping("typeList")
    public Result<?> pointTypeList() {
        return Result.success(EnumUtils.toList(UserOpt.class,"desc","code"));
    }

}
